/**
 * 	题型为问题+故事使用 故事不需要重复读 
 */
export const story = {
	data() {
		return {
			storyEnd: false //故事是否播放完毕
		}
	},
	/**
	 * 	分割故事和问题
	 */
	beforeMount() {
		const question = this.question.questionName.split('\n')
		this.question.questionName = question[1]
		this.question.store = question[0]
		this.assignment = this.question
	},
	computed: {
		questionWord() {
			return this.storyEnd ? this.assignment.questionName : this.assignment.store
		}
	},
	methods: {
		/**
		 * 	播放问题
		 *  将问题转换成音频播放
		 * 	优先播放故事再播放问题
		 * 	改变播放状态
		 */
		questionPlay: async function() {
			const data = await this.parseTextAudio({
				text: this.questionWord,
				speaker: this.assignment.audioSpeaker ? this.assignment.audioSpeaker : null
			})
			this.dialogueAudio({
				src: data,
				start: () => {
					this.questionPress = true
				},
				end: async () => {
					if (this.storyEnd) {
						this.questionPress = false
						return
					}
					const timer = setTimeout(() => {
						this.storyEnd = true
						this.questionPlay()
					}, 1000)
					this.$once('hook:beforeDestroy', function() {
						clearInterval(timer)
					})
				}
			})
		}
	}
}
